//
//  XLSwitchCompanyPresenter.m
//  industry
//
//  Created by xl on 2020/11/26.
//  Copyright © 2020 Haier. All rights reserved.
//

#import "XLSwitchCompanyPresenter.h"
#import "XLSwitchCompanyPresenterProtocol.h"
#import "XLCompanyModel.h"
#import "XLSwitchCompanyViewProtocol.h"

@interface XLSwitchCompanyPresenter ()<XLSwitchCompanyPresenterProtocol>

@end
@implementation XLSwitchCompanyPresenter

- (void)dealloc {
    XLLog(@"XLSwitchCompanyPresenter dealloc");
}

#pragma mark - XLSwitchCompanyPresenterProtocol
- (void)requestCompanyList {
    XLHttpRequest *request = [[XLHttpRequest alloc] init];
    WEAKSELF
    [request requestWithMethod:XLHttpMedthTypeGET url:XLCompanyListUrl params:nil isExtraParams:NO successBlock:^(NSDictionary *dict) {
        STRONGSELF
        id data = [dict objectForKey:@"data"];
        if ([data isKindOfClass:[NSArray class]]) {
            NSArray *temArr = [XLCompanyModel mj_objectArrayWithKeyValuesArray:data];
            XLSend(strongSelf.baseController.cView, XLSwitchCompanyViewProtocol, refreshTableView:temArr);
        }
    } failBlock:^(XLServerRequestsStatus status, XLNetworkReachabilityStatus reachability, NSError *error, NSDictionary *dict) {
        
    }];
}

- (void)handleCellData:(id)cellData {
    if ([cellData isKindOfClass:[XLCompanyModel class]]) {
        XLCompanyModel *model = (XLCompanyModel *)cellData;
        XL_UserInfoData.lastLoginCompany = model.firmId.stringValue;
        XL_UserInfoData.lastLoginCompanyName = model.firmName;
        [[XLUserData sharedXLUserData] saveCurrentUserInfo:XL_UserInfoData];
        [self.baseController.navigationController popViewControllerAnimated:YES];
    }
}

@end
